package com.example.work1;

import androidx.appcompat.app.AppCompatActivity;

import android.app.ListActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

public class MainActivity2 extends ListActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //创建命名列表
        String[] ctype = new String[]{MainActivity.ac+"1",MainActivity.ac+"2",MainActivity.ac+"3",
                MainActivity.ac+"4",MainActivity.ac+"5"};

        //创建列表项适配器
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
                android.R.layout.simple_list_item_1,ctype);
        setListAdapter(adapter);
    }
    @Override
    protected void onListItemClick(ListView l,View v,int position,long id){
        super.onListItemClick(l,v,position,id);
        String result = l.getItemAtPosition(position).toString();//获取选项的值
        Toast.makeText(MainActivity2.this, "您选择了第"+result.charAt(result.length()-1)+"项",
                Toast.LENGTH_SHORT).show();//显示提示消息框
    }
}